package com.zzl.bonds.ticket.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzl.bonds.ticket.dao.TicketCirculationRecordDao;
import com.zzl.bonds.ticket.dto.TickecirculationRecordAddDto;
import com.zzl.bonds.ticket.dto.TickecirculationRecordUpdateDto;
import com.zzl.bonds.ticket.entity.TickecirCulationRecordEntity;
import com.zzl.bonds.ticket.service.TicketCirculationRecordService;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.serurity.entity.User;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Query;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 统计开立 转让 融资成功的 金额
 *
 * @author sunpp
 * @date 2022-02-16 14:04:05
 */
@Service("ticketCirculationRecordService")
public class TicketCirculationRecordServiceImpl extends ServiceImpl<TicketCirculationRecordDao, TickecirCulationRecordEntity> implements TicketCirculationRecordService {

    /**
    * 分页查询
    *
    * @param params 查询参数
    * @return 分页数据
    */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TickecirCulationRecordEntity> page = this.page(
                new Query<TickecirCulationRecordEntity>().getPage(params),
                new QueryWrapper<>()
        );

        return new PageUtils(page);
    }

    /**
     * 新增
     *
     * @param tickecirculationRecordAddDto 新增实体
     * @param user 当前登录用户
     * @throws SysException 业务异常
     */
    @Override
    public void saveTickecirculationRecord(TickecirculationRecordAddDto tickecirculationRecordAddDto, User user) throws SysException {
        TickecirCulationRecordEntity tickecirculationRecordEntity = new TickecirCulationRecordEntity();
        BeanUtils.copyProperties(tickecirculationRecordAddDto, tickecirculationRecordEntity);
        tickecirculationRecordEntity.setCreatorId(user.getId());
        if(!this.save(tickecirculationRecordEntity)){
            throw new SysException("A00001", "保存失败！");
        }
    }

    /**
     * 修改
     *
     * @param tickecirculationRecordUpdateDto 修改实体
     * @param user 当前登录用户
     * @throws SysException 业务异常
     */
    @Override
    public void updateTickecirculationRecordById(TickecirculationRecordUpdateDto tickecirculationRecordUpdateDto, User user) throws SysException {
        TickecirCulationRecordEntity tickecirculationRecordEntity = new TickecirCulationRecordEntity();
        BeanUtils.copyProperties(tickecirculationRecordUpdateDto, tickecirculationRecordEntity);
        tickecirculationRecordEntity.setUpdaterId(user.getId());
        if(!this.updateById(tickecirculationRecordEntity)){
            throw new SysException("A00002", "修改失败！");
        }
    }

}